// /////////////////////////////////////////////////////////////////////////////
//
// Name:            asTerrainComponent.cpp
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Binds the TerrainComponent class to AngelScript
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

// Include files
#include "asTerrainComponent.h"

#ifdef __COMPILE_WITH_ANGELSCRIPT__

#include "../../ScriptHelper.h"
#include "asSceneComponent.h"

#include "../../../components/scene/TerrainComponent.h"


//! Reference factory for the TerrainComponent class.
TerrainComponent* createTerrainComponent(Entity *parent)
{
    return new TerrainComponent(parent);
}

//! Reference factory for the TerrainComponent class.
TerrainComponent* createTerrainComponent(Entity *parent, const std::string &fileName,
                                         const vector3df &scale, const SColor &vertexColor,
                                         s32 maxLOD, s32 smoothFactor)
{
    return new TerrainComponent(parent, fileName, scale, vertexColor, maxLOD, smoothFactor);
}

//! Binds the TerrainComponent class to AngelScript.
void bindTerrainComponent(asIScriptEngine *engine)
{
    // Forward declarations.
    int r;

    // Bind TerrainComponent class.
    r = engine->RegisterObjectType("TerrainComponent", sizeof(TerrainComponent), asOBJ_REF); assert(r >= 0);

    // Bind inherited functions.
    bindSceneComponentBase<TerrainComponent>(engine, "TerrainComponent");

    // Set TerrainComponent behaviour.
    r = engine->RegisterObjectBehaviour("TerrainComponent", asBEHAVE_FACTORY, "TerrainComponent@ f(Entity @+)",
                                        asFUNCTIONPR(createTerrainComponent, (Entity*), TerrainComponent*),
                                        asCALL_CDECL); assert(r >= 0);
    r = engine->RegisterObjectBehaviour("TerrainComponent", asBEHAVE_FACTORY, "TerrainComponent@ f(Entity @+, " \
                                        "const string &in, const vector3df &in, const SColor &in, s32, s32)",
                                        asFUNCTIONPR(createTerrainComponent, (Entity*, const std::string &,
                                        const vector3df &, const SColor &, s32, s32), TerrainComponent*),
                                        asCALL_CDECL); assert(r >= 0);

    r = engine->RegisterObjectMethod("TerrainComponent", "TerrainComponent& opAssign(const TerrainComponent &in)",
                                     asFUNCTION(assignT<TerrainComponent>), asCALL_CDECL_OBJFIRST); assert(r >= 0);

    // Bind TerrainComponent class functions.
    r = engine->RegisterObjectMethod("TerrainComponent", "const aabbox3df& getBoundingBox(s32, s32)",
                                     asMETHODPR(TerrainComponent, getBoundingBox, (s32, s32) const, const aabbox3df&),
                                     asCALL_THISCALL); assert(r >= 0);
    r = engine->RegisterObjectMethod("TerrainComponent", "f32 getHeight(f32, f32)",
                                     asMETHOD(TerrainComponent, getHeight), asCALL_THISCALL); assert(r >= 0);
    r = engine->RegisterObjectMethod("TerrainComponent", "const vector3df& getTerrainCenter()",
                                     asMETHOD(TerrainComponent, getTerrainCenter), asCALL_THISCALL); assert(r >= 0);
    r = engine->RegisterObjectMethod("TerrainComponent", "bool loadHeightMap(const string &in, const SColor &in, s32)",
                                     asMETHOD(TerrainComponent, loadHeightMap), asCALL_THISCALL); assert(r >= 0);
    r = engine->RegisterObjectMethod("TerrainComponent", "void scaleTexture(f32, f32)",
                                     asMETHOD(TerrainComponent, scaleTexture), asCALL_THISCALL); assert(r >= 0);
}

#endif // __COMPILE_WITH_ANGELSCRIPT__

// End of File
